home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fsdomain / RCS / fsdomain.c,v < prev    next >
Text File  |  1992-03-12  |  13KB  |  558 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     92.03.12.16.36.36;  author voelker;  state Exp;
  11. branches ;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     91.10.11.14.37.03;  author voelker;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     91.10.11.14.31.36;  author voelker;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     91.10.11.14.27.33;  author voelker;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     91.10.07.18.11.41;  author voelker;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @reads and writes the domain prefix of unmounted disk partitions
  37. @
  38.  
  39.  
  40. 1.5
  41. log
  42. @added options to change domain number and serverID, or
  43. print out file system structure info in addition to
  44. just changing the domain prefix.
  45.  
  46. @
  47. text
  48. @/*
  49.  * fsdomain.c --
  50.  *
  51.  *     Read and possibly change the domain prefix of a file system.
  52.  *  
  53.  */
  54.  
  55. #ifndef lint
  56. static char rcsid[] = "$Header: /sprite/src/cmds/fsdomain/RCS/fsdomain.c,v 1.4 91/10/11 14:37:03 voelker Exp Locker: voelker $";
  57. #endif not lint
  58.  
  59. #include "sprite.h"
  60. #include "sys/file.h"
  61. #include "stdio.h"
  62. #include "errno.h"
  63.  
  64. #include "disk.h"
  65. #include "option.h"
  66.  
  67. /*
  68.  * The size is declared in <kernel/lfsSuperBlock.h>, and is 64
  69.  * bytes.
  70.  */
  71. #define MAX_LFS_DOMAIN_PREFIX 63  
  72. /*
  73.  * OFS_SUMMARY_PREFIX_LENGTH is defined in <kernel/ofs.h>
  74.  */
  75. #define MAX_OFS_DOMAIN_PREFIX OFS_SUMMARY_PREFIX_LENGTH - 1
  76.  
  77. #define INV_DOMAIN -9999
  78. int     newDomainNum = INV_DOMAIN;
  79. int     newServerID = -1;
  80. Boolean previousCheckPoint = FALSE;
  81. Boolean printInfo = FALSE;
  82. char    *newDomain = NULL;
  83.  
  84. Option optionArray[] = {
  85.     {OPT_DOC, "", (Address)NIL,
  86.      "fsdomain device"},
  87.     {OPT_STRING, "name", (char *)&newDomain,
  88.          "New domain name"},
  89.     {OPT_INT, "d", (Address)&newDomainNum,
  90.      "New domain number"},
  91.     {OPT_INT, "id", (Address)&newServerID,
  92.      "New server ID"},
  93.     {OPT_TRUE, "print", (Address)&printInfo,
  94.      "Print out values of file system structures."},
  95.     {OPT_TRUE, "prev", (Address)&previousCheckPoint,
  96.      "Use the previous (older) checkpoint.  Useful for when the kernel\n\tand the disk get out of sync on LFS checkpoints."}
  97. };
  98.  
  99. static int numOptions = sizeof(optionArray) / sizeof(Option);
  100.  
  101. /*
  102.  *----------------------------------------------------------------------
  103.  *
  104.  * ChangeLfsDomainPrefix
  105.  *
  106.  *      Change the domain prefix of an LFS file system.  If
  107.  *      newDomain is NULL, the old domain prefix is printed to stdout.
  108.  *
  109.  * Results:
  110.  *      None.
  111.  *
  112.  * Side effects:
  113.  *    Writes the new domain prefix to the LFS file system on stream;
  114.  *      Prints to stdout.
  115.  *
  116.  *----------------------------------------------------------------------
  117.  */
  118. void
  119. ChangeLfsDomainPrefix(stream, labelPtr, deviceName, newDomain)
  120.     int stream;
  121.     Disk_Label *labelPtr;
  122.     char *deviceName;
  123.     char *newDomain;
  124. {
  125.     LfsCheckPointHdr *headerPtr;
  126.     int              len;
  127.     int              status;
  128.     int              area = -1;
  129.     Boolean          writeCheckPoint = FALSE;
  130.  
  131.     headerPtr = Disk_ReadLfsCheckPointHdr(stream, labelPtr, &area);
  132.     printf("Latest checkpoint is #%d", area);
  133.     if (previousCheckPoint == TRUE) {
  134.     area = (area == 0) ? 1 : 0;
  135.     printf("...using #%d instead.\n", area);
  136.     headerPtr = Disk_ReadLfsCheckPointHdr(stream, labelPtr, &area);
  137.     } else {
  138.     putchar('\n');
  139.     }
  140.     if (headerPtr == NULL || area < 0 || area > 1) {
  141.     return;
  142.     }
  143.     if (printInfo) {
  144.     LfsCheckPointTrailer *trailerPtr;
  145.  
  146.     printf("LFS Checkpoint Header on %s:\n\n", deviceName);
  147.     Disk_PrintLfsCheckPointHdr(headerPtr);
  148.     printf("\nLFS Checkpoint Regions on %s:\n\n", deviceName);
  149.     Disk_ForEachCheckPointRegion(headerPtr, 
  150.                      Disk_PrintLfsCheckPointRegion);
  151.     printf("\nLFS Checkpoint Trailer on %s:\n\n", deviceName);
  152.     trailerPtr = Disk_LfsCheckPointTrailer(headerPtr);
  153.     Disk_PrintLfsCheckPointTrailer(trailerPtr);
  154.     return;
  155.     }
  156.     if (newDomain != NULL) {
  157.     len = strlen(newDomain);
  158.     if (len > MAX_LFS_DOMAIN_PREFIX) {
  159.         printf("The LFS limits domain prefixes to %d characters.\n",
  160.            MAX_LFS_DOMAIN_PREFIX);
  161.         printf("%s is %d characters too long.\n", newDomain,
  162.            len - MAX_LFS_DOMAIN_PREFIX);
  163.         return;
  164.     }
  165.     sprintf(headerPtr->domainPrefix, "%s", newDomain); 
  166.     writeCheckPoint = TRUE;
  167.     }
  168.     if (newDomainNum != INV_DOMAIN) {
  169.     headerPtr->domainNumber = newDomainNum;
  170.     writeCheckPoint = TRUE;
  171.     }
  172.     if (newServerID > 0) {
  173.     headerPtr->serverID = newServerID;
  174.     writeCheckPoint = TRUE;
  175.     }
  176.     if (writeCheckPoint) {
  177.     status = Disk_WriteLfsCheckPointHdr(stream, headerPtr, area, 
  178.                         labelPtr); 
  179.     if (status != 0) {
  180.         fprintf(stderr, "fsdomain: could not write LFS checkpoint ");
  181.         fprintf(stderr, "header: %s\n", deviceName);
  182.         free((Address)headerPtr);
  183.         return;
  184.     }
  185.     }    
  186.     printf("%s:\t%s\n", deviceName, headerPtr->domainPrefix);
  187.     printf("Server ID:\t%d\n", headerPtr->serverID);
  188.     printf("Domain number:\t%d\n", headerPtr->domainNumber);
  189.     free((Address)headerPtr);
  190.     return;
  191. }
  192.  
  193. /*
  194.  *----------------------------------------------------------------------
  195.  *
  196.  * ChangeOfsDomainPrefix
  197.  *
  198.  *      Change the domain prefix of an OFS file system.  If
  199.  *      newDomain is NULL, the old domain prefix is printed to stdout.
  200.  *
  201.  * Results:
  202.  *      None.
  203.  *
  204.  * Side effects:
  205.  *    Writes the new domain prefix to the OFS file system on stream,
  206.  *      modifying the Ofs_SummaryInfo;
  207.  *      Prints to stdout.
  208.  *
  209.  *----------------------------------------------------------------------
  210.  */
  211. ChangeOfsDomainPrefix(stream, labelPtr, deviceName, newDomain)
  212.     int stream;
  213.     Disk_Label *labelPtr;
  214.     char *deviceName;
  215.     char *newDomain;
  216. {
  217.     Ofs_SummaryInfo  *summaryPtr;
  218.     Ofs_DomainHeader *domainPtr;
  219.     int              len;
  220.     int              status;
  221.     Boolean          writeSummary = FALSE;
  222.     Boolean          writeDomain = FALSE;
  223.  
  224.     summaryPtr = Disk_ReadSummaryInfo(stream, labelPtr);
  225.     if (summaryPtr == NULL) {
  226.     printf(stderr, "fsdomain: couldn't read Ofs_SummaryInfo\n");
  227.     return;
  228.     }
  229.     domainPtr = Disk_ReadDomainHeader(stream, labelPtr);
  230.     if (domainPtr == NULL) {
  231.     printf(stderr, "fsdomain: couldn't read Ofs_DomainHeader\n");
  232.     return;
  233.     }
  234.     if (printInfo) {
  235.     printf("OFS Domain Header on %s:\n\n", deviceName);
  236.     Disk_PrintDomainHeader(domainPtr);
  237.     printf("\nOFS Summary Info on %s:\n\n", deviceName);
  238.     Disk_PrintSummaryInfo(summaryPtr);
  239.     return;
  240.     }
  241.     if (newDomain != NULL) {
  242.     len = strlen(newDomain);
  243.     if (len > MAX_OFS_DOMAIN_PREFIX) {
  244.         printf("The OFS limits domain prefixes to %d characters.\n",
  245.            MAX_OFS_DOMAIN_PREFIX);
  246.         printf("%s is %d characters too long.\n", newDomain,
  247.            len - MAX_OFS_DOMAIN_PREFIX);
  248.         free((Address)summaryPtr);
  249.         return;
  250.     }
  251.     sprintf(summaryPtr->domainPrefix, "%s", newDomain);
  252.     writeSummary = TRUE;
  253.     }
  254.     if (newDomainNum != INV_DOMAIN) {
  255.     summaryPtr->domainNumber = newDomainNum;
  256.     writeSummary = TRUE;
  257.     }
  258.     if (newServerID > 0) {
  259.     domainPtr->device.serverID = newServerID;
  260.     writeDomain = TRUE;
  261.     }
  262.     if (writeSummary) {
  263.     status = Disk_WriteSummaryInfo(stream, labelPtr, summaryPtr);
  264.     if (status != 0) {
  265.         fprintf(stderr, "fsdomain: could not write OFS summary ");
  266.         fprintf(stderr, "sector: %s\n", deviceName);
  267.         free((Address)summaryPtr);
  268.         return;
  269.     }
  270.     }
  271.     if (writeDomain) {
  272.     status = Disk_WriteDomainHeader(stream, labelPtr, domainPtr);
  273.     if (status != 0) {
  274.         fprintf(stderr, "fsdomain: could not write OFS domain ");
  275.         fprintf(stderr, "header: %s\n", deviceName);
  276.         free((Address)summaryPtr);
  277.         return;
  278.     }
  279.     }
  280.     printf("%s:\t%s\n", deviceName, summaryPtr->domainPrefix);
  281.     printf("Server ID:\t%d\n", domainPtr->device.serverID);
  282.     printf("Domain number:\t%d\n", summaryPtr->domainNumber);
  283.     free((Address)summaryPtr);
  284.     return;
  285. }
  286.  
  287. /*
  288.  *----------------------------------------------------------------------
  289.  *
  290.  * main --
  291.  *
  292.  *      Open the device stream, read and possibly change the
  293.  *      domain prefix of the file system found on the stream.
  294.  *
  295.  * Results:
  296.  *      None.
  297.  *
  298.  * Side effects:
  299.  *    Prints to stdout.
  300.  *
  301.  *----------------------------------------------------------------------
  302.  */
  303. void
  304. main(argc, argv)
  305.     int argc;
  306.     char *argv[];
  307. {
  308.     int        stream;
  309.     int        fstype;
  310.     Disk_Label *labelPtr;
  311.     char       *deviceName;
  312.  
  313.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  314.     if (argc != 2) {
  315.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  316.     exit(FAILURE);
  317.     }
  318.     deviceName = argv[1];
  319.     /*
  320.      * If there are no new values, then just report the current ones.
  321.      */
  322.     if (newDomain == NULL && newDomainNum == INV_DOMAIN && newServerID < 0) {
  323.     stream = open(deviceName, O_RDONLY, 0);
  324.     } else {
  325.     stream = open(deviceName, O_RDWR, 0);
  326.     }
  327.     if (stream < 0) {
  328.     perror("opening device");
  329.     exit(FAILURE);
  330.     }
  331.  
  332.     labelPtr = Disk_ReadLabel(stream);
  333.     if (labelPtr == NULL) {
  334.     printf("fsdomain: cannot find label on device %s.  ", deviceName);
  335.     printf("Is the label\non the disk of the correct type for");
  336.     printf("the machine being used?\n");
  337.     }
  338.  
  339.     fstype = Disk_HasFilesystem(stream, labelPtr);
  340.     switch (fstype) {
  341.     case DISK_HAS_OFS:
  342.     ChangeOfsDomainPrefix(stream, labelPtr, deviceName, newDomain);
  343.     break;
  344.     case DISK_HAS_LFS:
  345.     ChangeLfsDomainPrefix(stream, labelPtr, deviceName, newDomain);
  346.     break;
  347.     default:
  348.     printf("%s: no file system found.\n", deviceName);
  349.     break;
  350.     }
  351.     free((Address)labelPtr);
  352. }
  353. @
  354.  
  355.  
  356. 1.4
  357. log
  358. @explicitly cast arguments to free to Address so that lint
  359. would stop complaining
  360. @
  361. text
  362. @d9 1
  363. a9 1
  364. static char rcsid[] = "$Header: /sprite/src/cmds/fsdomain/RCS/fsdomain.c,v 1.3 91/10/11 14:31:36 voelker Exp Locker: voelker $";
  365. d30 7
  366. d39 11
  367. a49 1
  368.      "fsdomain device [new domain prefix]"}
  369. d51 1
  370. d81 2
  371. a82 1
  372.     int              area;
  373. d85 8
  374. d96 14
  375. a109 8
  376.     /*
  377.      * If the new domain name is NULL, just print out the old one.
  378.      * If it isn't NULL, try to change the domain name and report
  379.      * the change.
  380.      */
  381.     if (newDomain == NULL) {
  382.     printf("%s: %s\n", deviceName, headerPtr->domainPrefix);
  383.     } else {
  384. d119 11
  385. d138 4
  386. a141 2
  387.     printf("%s: %s\n", deviceName, newDomain);
  388.     }
  389. d149 1
  390. a149 1
  391.  * ChangefsDomainPrefix
  392. d170 6
  393. a175 3
  394.     Ofs_SummaryInfo *summaryPtr;
  395.     int             len;
  396.     int             status;
  397. d179 13
  398. d194 1
  399. a194 8
  400.     /*
  401.      * If the new domain name is NULL, just print out the old one.
  402.      * If it isn't NULL, try to change the domain name and report
  403.      * the change.
  404.      */
  405.     if (newDomain == NULL) {
  406.     printf("%s: %s\n", deviceName, summaryPtr->domainPrefix);
  407.     } else {
  408. d205 11
  409. a222 1
  410.     printf("%s: %s\n", deviceName, newDomain);
  411. d224 12
  412. a264 1
  413.     char       *newDomain;
  414. d267 1
  415. a267 1
  416.     if (argc < 2 || argc > 3) {
  417. a271 5
  418.     if (argc == 3) {
  419.     newDomain = argv[2];
  420.     } else {
  421.     newDomain = NULL;
  422.     }
  423. d273 1
  424. a273 1
  425.      * if newDomain is NULL, then just report the current name
  426. d275 1
  427. a275 1
  428.     if (newDomain == NULL) {
  429. @
  430.  
  431.  
  432. 1.3
  433. log
  434. @forgot to change "mydisk.h" to "disk,h"
  435. @
  436. text
  437. @d9 1
  438. a9 1
  439. static char rcsid[] = "$Header: /sprite/src/cmds/fsdomain/RCS/fsdomain.c,v 1.2 91/10/11 14:27:33 voelker Exp Locker: voelker $";
  440. d91 1
  441. a91 1
  442.         free(headerPtr);
  443. d96 1
  444. a96 1
  445.     free(headerPtr);
  446. d146 1
  447. a146 1
  448.         free(summaryPtr);
  449. d154 1
  450. a154 1
  451.         free(summaryPtr);
  452. d159 1
  453. a159 1
  454.     free(summaryPtr);
  455. d233 1
  456. a233 1
  457.     free(labelPtr);
  458. @
  459.  
  460.  
  461. 1.2
  462. log
  463. @first version ready for release --
  464. if no new prefix is specified, then it just reports the current
  465. one and exits.
  466.  
  467. Does not check to see if the file system is mounted.
  468.  
  469. no command line options
  470. @
  471. text
  472. @d9 1
  473. a9 1
  474. static char rcsid[] = "$Header: /user6/voelker/fsdomain/RCS/fsdomain.c,v 1.1 91/10/07 18:11:41 voelker Exp Locker: voelker $";
  475. d17 1
  476. a17 1
  477. #include "mydisk.h"
  478. @
  479.  
  480.  
  481. 1.1
  482. log
  483. @Initial revision
  484. @
  485. text
  486. @d9 1
  487. a9 1
  488. static char rcsid[] = "$Header$"
  489. d12 1
  490. d32 1
  491. a32 1
  492.      "fsdomain device [domain]"}
  493. d39 1
  494. a39 1
  495.  * ChangeLfsDoaminPrefix
  496. d41 2
  497. a42 3
  498.  *      Prints the domain prefix, the domain number,
  499.  *      the SpriteID, the start cylinder and size, and the index of
  500.  *      the LFS partition found on the stream
  501. d48 2
  502. a49 1
  503.  *    Prints to stdout.
  504. d53 1
  505. a53 1
  506. int
  507. d63 1
  508. d65 4
  509. a68 4
  510. /*    headerPtr = Disk_ReadLfsCheckPointHdr(stream, labelPtr);
  511.     if (headerPtr == NULL) {
  512.     return FAILURE;
  513.     } */
  514. d83 1
  515. a83 1
  516.         return FAILURE;
  517. d86 2
  518. a87 4
  519. /*
  520.  * need area!!!
  521.  */
  522. /*    status = Disk_WriteLfsCheckPointHdr(stream, headerPtr, 0, labelPtr); */
  523. d92 1
  524. a92 1
  525.         return FAILURE;
  526. d97 1
  527. a97 1
  528.     return SUCCESS;
  529. d103 1
  530. a103 1
  531.  * ChangeOfsDomainPrefix --
  532. d105 2
  533. a106 3
  534.  *      Prints the domain prefix, the domain number,
  535.  *      the SpriteID, the start cylinder and size, and the index of
  536.  *      the OFS partition found on the stream.
  537. d112 3
  538. a114 1
  539.  *    Prints to stdout.
  540. a117 1
  541. int
  542. d130 1
  543. a130 1
  544.     return FAILURE;
  545. d132 5
  546. d147 1
  547. a147 1
  548.         return FAILURE;
  549. d155 1
  550. a155 1
  551.         return FAILURE;
  552. d160 1
  553. a160 1
  554.     return SUCCESS;
  555. d201 3
  556. d211 1
  557. @
  558.